package com.quan.mobile.common.configuration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.quan.configuration.properties.WxConfigProperties;

import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;

/**
 * 微信公共配置类
 * @author yhaoquan
 *
 */
@Configuration
public class WeixinConfiguration {

	@Autowired
	private WxConfigProperties properties;
	
	@Bean
	public WxMpInMemoryConfigStorage getWxMpInMemoryConfigStorage() {
		//配置微信基本信息 APPID AppSecret Token
		WxMpInMemoryConfigStorage config = new WxMpInMemoryConfigStorage() ;
		config.setAppId(properties.getAppId());
		config.setSecret(properties.getAppSecret());
		config.setToken(properties.getToken());
		
		return config ;
	}
	
	@Bean
	public WxMpService getWxMpService() {
		WxMpService wxMpService = new WxMpServiceImpl() ;
		wxMpService.setWxMpConfigStorage(getWxMpInMemoryConfigStorage());
		return wxMpService ;
	}
	
}
